package org.quasar.airNova.presentationLayer;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Set;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.quasar.airNova.businessLayer.CalendarDate;
import org.quasar.airNova.businessLayer.CartaoCredito;
import org.quasar.airNova.businessLayer.Cliente;

public class AssociarCartaoCredito extends JPanel {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private JTextField nData;
		private Gui gui;
		private JComboBox nCliente;
		private JTextField nCartaoCredito;

		/**
		 * Create the panel.
		 * @param gui 
		 */
		public AssociarCartaoCredito(Gui gui) {
			setGui(gui);
			setLayout(new BorderLayout(0, 0));
			this.setSize(500, 350);
			JPanel panel = new JPanel();
			add(panel, BorderLayout.CENTER);
			panel.setLayout(null);
			
			JLabel lblNewLabel = new JLabel("N\u00FAmero de Cliente");
			lblNewLabel.setBounds(40, 76, 151, 14);
			panel.add(lblNewLabel);
			
			JLabel lblNmeroCartaoDe = new JLabel("Nr Cartao de Credito");
			lblNmeroCartaoDe.setBounds(40, 101, 126, 14);
			panel.add(lblNmeroCartaoDe);
			
			JLabel lbData = new JLabel("Data <dd-mm-yy>");
			lbData.setBounds(40, 126, 126, 14);
			panel.add(lbData);
			
			nData = new JTextField();
			nData.setBounds(231, 123, 203, 20);
			panel.add(nData);
			nData.setColumns(10);
			
			JButton btnNewButton_2 = new JButton("Apagar Campos");
			btnNewButton_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					nData.setText("");
				}
			});
			btnNewButton_2.setBounds(251, 217, 126, 23);
			panel.add(btnNewButton_2);
			
			JButton btnNewButton = new JButton("Submeter");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(nCliente.getSelectedItem() != null && nCartaoCredito.getText().length() != 0 && nData.getText().length() != 0)
					AirNova_Database.associarCartaoCredito((String) nCliente.getSelectedItem(), nCartaoCredito.getText(), nData.getText());					
				}
			});
			btnNewButton.setBounds(44, 217, 98, 23);
			panel.add(btnNewButton);
			
			JButton btnNewButton_1 = new JButton("Cancelar");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					getGui().getTabbedPane().removeTabAt(getGui().getTabbedPane().getSelectedIndex());
				}
			});
			btnNewButton_1.setBounds(152, 217, 89, 23);
			panel.add(btnNewButton_1);
			
			JLabel lblNewLabel_3 = new JLabel("Associar Cartao Cr\u00E9dito");
			lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 17));
			lblNewLabel_3.setBounds(30, 24, 175, 32);
			panel.add(lblNewLabel_3);
			if(Tools.getClienteCodigos() != null)
			nCliente = new JComboBox(Tools.getClienteCodigos());
			else
			nCliente = new JComboBox();
			
			nCliente.setBounds(231, 73, 203, 20);
			panel.add(nCliente);
			
			nCartaoCredito = new JTextField();
			nCartaoCredito.setColumns(10);
			nCartaoCredito.setBounds(231, 98, 203, 20);
			panel.add(nCartaoCredito);

		}

		public Gui getGui() {
			return gui;
		}
		
	

		public void setGui(Gui gui) {
			this.gui = gui;
		}
}
